package com.xgkj.diyiketang.task;

import com.alibaba.fastjson.JSONObject;
import com.xgkj.diyiketang.http.CouponHttpRequest;
import com.xgkj.diyiketang.http.CouponHttpResponse;
import com.xgkj.diyiketang.http.engine.CouponHttpBaseTask;
import com.xgkj.diyiketang.http.engine.TaskResultCode;

/**
 * Created by windo on 16/9/1.
 */
public class BuyGoldCoinTask extends CouponHttpBaseTask {

    private String type;
    private String money;
    public BuyGoldCoinTask(String mtype, String qian) {
        super();
        type = mtype;
        money = qian;
    }

    @Override
    protected void processResponseData(CouponHttpResponse response) {
        JSONObject jsonObject = response.getBody();
        String coinBalance = jsonObject.getString("orderNo");
        notifyTaskCompleted(TaskResultCode.SUCCESS,coinBalance);
    }

    @Override
    protected void prepareRequest() {
        super.prepareRequest();
        if (mPhase == TASK_PHASE_INIT){
            CouponHttpRequest request = new CouponHttpRequest();
            request.setApiNo(ApiNo.BUY_GOLD_COIN);
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("type",type);
            jsonObject.put("money",money);
            jsonObject.put("system",0);
            request.setData(jsonObject.toString());
            addRequest(request);
        }
    }
}
